/*
 * @author:   liaohui
 * @brief:    Control the ws2812b led with Arduino Interrupt function. 
 * @thirdLib: Adafruit_NeoPixel.h     
 */
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif


#define PIN           43  //control the ws2812
#define NUMPIXELS     8   //the number of ws2812
#define DELAYVAL      500 //delay time

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); //class Adafruit_NeoPixel init


unsigned int i = 0;

int color[8] = {0xef5b9c,0xb2d235,0x009ad6,0x33a3dc,0x2585a6,0x8f4b38,0xffc20e,0x293047}; //init the color of ws2812, hex type

void click();

void setup() {

/* @func:   attachInterrupt(digitalPinToInterrupt(pin), ISR, mode)
 * @Mega2560 pinNumber:  
 *          2, 3, 18, 19, 20, 21
 * @parm:   LOW,HIGH,CHANGE,RISING,FALLING
 */
  attachInterrupt(digitalPinToInterrupt(19),click,RISING);  
  pixels.setBrightness(5);
  pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED必需的)
  pixels.clear();
}

void loop() {

}

void click()
{
    pixels.setPixelColor(i,color[i]);
    i++;
    if(i == 9){i=0;pixels.clear();}
    pixels.show();
}
